package bb.lanxing.model.database;

import android.os.Parcel;
import android.os.Parcelable;

//import com.orm.SugarRecord;
//import com.orm.dsl.Ignore;
//import com.orm.dsl.Table;
//import com.orm.query.Select;

import org.json.JSONObject;
import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;

import java.util.List;

import bb.lanxing.util.JsonUtil;


public class MapItem extends LitePalTableBase implements Parcelable {
    public static final Creator<MapItem> CREATOR = new Creator<MapItem>() {
        @Override
        public MapItem createFromParcel(Parcel source) {
            return new MapItem(source);
        }

        @Override
        public MapItem[] newArray(int size) {
            return new MapItem[size];
        }
    };
    private int blingbling;

    private boolean isSelected;

    private int mapImage;
    private int mapItemId;
    private String mapType;
    private String name;
    private int openStatus;
    private int proLevel;
    private String proName;
    private String thumbnail;
    private String tileLink;
    private String tileLinkv1;
    private String trackColor;

//    public static void deleteAll(Class<MapItem> mapItemClass){
//
//        LitePal.deleteAll(MapItem.class);
//
//    }

    @Override
    public int describeContents() {
        return 0;
    }

    public MapItem() {
    }

    public MapItem(JSONObject jSONObject) {
        setName(JsonUtil.getStringValue("name", jSONObject));
        setMapItemId(JsonUtil.getIntegerValue("id", jSONObject));
        setMapType(JsonUtil.getStringValue("map_type", jSONObject));
        setTileLink(JsonUtil.getStringValue("tile_link", jSONObject));
        setTileLinkv1(JsonUtil.getStringValue("tile_linkv1", jSONObject));
        setThumbnail(JsonUtil.getStringValue("thumbnail", jSONObject));
        setProLevel(JsonUtil.getIntegerValue("pro_level", jSONObject));
        setProName(JsonUtil.getStringValue("pro_name", jSONObject));
        setTrackColor(JsonUtil.getStringValue("track_color", jSONObject));
        setOpenStatus(JsonUtil.getIntegerValue("open_status", jSONObject));
        setBlingbling(JsonUtil.getIntegerValue("blingbling", jSONObject));
    }

    public static List<MapItem> getByMapType(String str) {

        List<MapItem> l = LitePal.where("map_type=?", str).find(MapItem.class);
        return l;

        //return Select.from(MapItem.class).where(" map_type = ?", new String[]{str}).list();
    }

    public static MapItem getByMapTypeId(int i) {

        String mapItemId = String.valueOf(i);
        MapItem m = LitePal.where("mapItemId=?", mapItemId).findFirst(MapItem.class);
        return m;

//        return (MapItem) Select.from(MapItem.class).where(" map_item_id = ?", new String[]{String.valueOf(i)}).first();
    }



    protected MapItem(Parcel parcel) {
        this.name = parcel.readString();
        this.proName = parcel.readString();
        this.mapItemId = parcel.readInt();
        this.mapType = parcel.readString();
        this.tileLink = parcel.readString();
        this.tileLinkv1 = parcel.readString();
        this.thumbnail = parcel.readString();
        this.trackColor = parcel.readString();
        this.proLevel = parcel.readInt();
        this.mapImage = parcel.readInt();
        this.openStatus = parcel.readInt();
        this.blingbling = parcel.readInt();
        this.isSelected = parcel.readByte() != 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.name);
        parcel.writeString(this.proName);
        parcel.writeInt(this.mapItemId);
        parcel.writeString(this.mapType);
        parcel.writeString(this.tileLink);
        parcel.writeString(this.tileLinkv1);
        parcel.writeString(this.thumbnail);
        parcel.writeString(this.trackColor);
        parcel.writeInt(this.proLevel);
        parcel.writeInt(this.mapImage);
        parcel.writeInt(this.openStatus);
        parcel.writeInt(this.blingbling);
        parcel.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
    }



    public String getName() {
        return this.name;
    }

    public void setName(String str) {
        this.name = str;
    }

    public int getMapItemId() {
        return this.mapItemId;
    }

    public void setMapItemId(int i) {
        this.mapItemId = i;
    }

    public String getMapType() {
        return this.mapType;
    }

    public void setMapType(String str) {
        this.mapType = str;
    }

    public String getThumbnail() {
        return this.thumbnail;
    }

    public void setThumbnail(String str) {
        this.thumbnail = str;
    }

    public String getTrackColor() {
        return this.trackColor;
    }

    public void setTrackColor(String str) {
        this.trackColor = str;
    }

    public int getProLevel() {
        return this.proLevel;
    }

    public void setProLevel(int i) {
        this.proLevel = i;
    }

    public boolean isSelected() {
        return this.isSelected;
    }

    public void setSelected(boolean z) {
        this.isSelected = z;
    }

    public int getMapImage() {
        return this.mapImage;
    }

    public void setMapImage(int i) {
        this.mapImage = i;
    }

    public String getProName() {
        return this.proName;
    }

    public void setProName(String str) {
        this.proName = str;
    }

    public String getTileLink() {
        return this.tileLink;
    }

    public void setTileLink(String str) {
        this.tileLink = str;
    }

    public String getTileLinkv1() {
        return this.tileLinkv1;
    }

    public void setTileLinkv1(String str) {
        this.tileLinkv1 = str;
    }

    public int getOpenStatus() {
        return this.openStatus;
    }

    public void setOpenStatus(int i) {
        this.openStatus = i;
    }

    public int getBlingbling() {
        return this.blingbling;
    }

    public void setBlingbling(int i) {
        this.blingbling = i;
    }


}
